import { Form, Input, Select, message, Card, Tree, Upload } from 'myselfantd';
import React from 'react';
import styles from './index.module.scss';
import { addConsumerCompany } from '@/services/api/enterprise';
import { AESencode } from '@/utils/common';

interface AddFormProps {
  mapPoint?: string;
  data?: any;
  onFinish: Function;
  viewmode: viewmode;
}
type viewmode = 'view' | 'add' | 'edit';
const App: React.FC<AddFormProps> = ({ data, onFinish: handleFinish, viewmode }) => {
  const handleSave = async (val: any) => {
    const password = AESencode(val.password);
    let res = await addConsumerCompany({ ...val, password });
    if (res) {
      message.success('创建成功');
    }
  };
  return (
    <div className={styles.addContent}>
      <Form.Layout
        viewmode={viewmode}
        data={{
          businessLicenseUrl: '1',
          companyName: '111111111111111111',
          cooperateType: 0,
          creditCode: '11111111111111111Z',
          email: 'zhoubichuan@123.com',
          menuList: [],
          nickname: 'zhoubc',
          password: '123Qwe@',
          phone: '18064034155',
          remark: '',
          username: 'zhoubc',
        }}
        request={handleSave}
        formItemData={[
          [
            {
              name: 'companyName',
              label: '农机名称',
              rules: [{ required: true, message: '企业名称必填' }],
              render: () => <Input placeholder="请输入" />,
            },
            {
              name: 'creditCode',
              label: '农机类型',
              rules: [{ required: true, message: '企业信用代码必填' }],
              render: () => <Input placeholder="请输入" />,
              editRender: () => <Input placeholder="请输入" />,
            },
          ],
          [
            {
              name: 'username',
              label: '所属品类',
              rules: [{ required: true, message: '企业账号必填' }],
              render: () => (
                <Select placeholder="请选择" allowClear>
                  <Select.Option value={0}>合同客户</Select.Option>
                  <Select.Option value={1}>临时客户</Select.Option>
                </Select>
              ),
              editRender: () => (
                <Select placeholder="请选择" allowClear>
                  <Select.Option value={0}>合同客户</Select.Option>
                  <Select.Option value={1}>临时客户</Select.Option>
                </Select>
              ),
            },
            {
              name: 'password',
              label: '所属系统',
              rules: [{ required: true, message: '农机数量必填' }],
              render: () => (
                <Select placeholder="请选择" allowClear>
                  <Select.Option value={0}>合同客户</Select.Option>
                  <Select.Option value={1}>临时客户</Select.Option>
                </Select>
              ),
              editRender: () => (
                <Select placeholder="请选择" allowClear>
                  <Select.Option value={0}>合同客户</Select.Option>
                  <Select.Option value={1}>临时客户</Select.Option>
                </Select>
              ),
            },
          ],
          [
            {
              name: 'email',
              label: '出厂编号',
              rules: [{ required: true, message: '联系邮箱必填' }],
              render: () => <Input placeholder="请输入" />,
              editRender: () => <Input disabled placeholder="请输入" />,
            },
            {
              name: 'cooperateType',
              label: '车架号',
              rules: [{ required: true, message: '合作类型必填' }],
              render: () => <Input placeholder="请输入" />,
              editRender: () => <Input disabled placeholder="请输入" />,
            },
          ],
          [
            {
              name: 'businessLicenseUrl1',
              label: '所属系统',
              rules: [{ required: true, message: '围栏名称必填' }],
              render: () => <Input placeholder="请输入" />,
            },
          ],
          [
            {
              name: 'businessLicenseUrl',
              label: '农机图片',
              rules: [{ required: true, message: '围栏名称必填' }],
              render: () => <Upload urlTemplate={`${UPLOAD_IMG_URL_NEW}/hxdfs/{0}`} />,
            },
          ],
          [
            {
              name: 'remark',
              label: '说 明',
              render: () => <Input.TextArea  showCount maxLength={512} />,
            },
          ],
        ]}
        onFinish={handleFinish}
      ></Form.Layout>
    </div>
  );
};

export default App;
